#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int q;
string s, t;

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    cin >> q;
    while (q--) {
        cin >> s >> t;
        if (t == "a") puts("1");
        else if (t.find("a") != string::npos) puts("-1");
        else {
            ll ans = 1ll << s.size();
            cout << ans << endl;
        }
    }
    return 0;
}